<?php
namespace app\admin\controller;

use app\common\model\Renzhen as RenzhenModel;
use app\common\model\Manager as ManagerModel;

/**
 * 法师认证控制器
 * Class Renzhen
 * @package app\admin\controller
 */
class Renzhen extends Base
{
    /**
     * [getIndex  充值列表]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function add()
    {
        $param = input('param.');
        $model = new ManagerModel();
        $rmodel = new RenzhenModel();

        if(!is_idcard($param['idcard']))
            return admin_json(-2,'身份证错误！');

        $tel = $model->getAllData(['tel'=>$param['tel']]);
        if(!empty($tel))
            return admin_json(-3,'已注册法师！');

        $idcard = $model->getAllData(['idcard'=>$param['idcard']]);
        if(!empty($idcard))
            return admin_json(-4,'该身份证号已注册法师！');
        try{
            $renzhen = $rmodel->findData($param['id'],'uid','id');
            $img = $param['zcard'].','.$param['fcard'].','.$param['jiedie'];
            if(empty($renzhen)){
                $data = array(
                    'type'=>1,
                    'idcard'=>$param['idcard'],
                    'fahao'=>$param['fahao'],
                    'siyuan'=>$param['siyuan'],
                    'card_pic'=>$img,
                    'addtime'=>date('Y-m-d H:i:s'),
                    'uid'=>$param['id'],
                    'sex'=>$param['sex'],
                    'addr'=>$param['addr'],
                    'zongpai'=>$param['zongpai'],
                    'phone'=>$param['phone'],
                    'isapp'=>2
                );
                $rmodel->addData($data);
            }else{
                $data = array(
                    'idcard'=>$param['idcard'],
                    'fahao'=>$param['fahao'],
                    'siyuan'=>$param['siyuan'],
                    'card_pic'=>$img,
                    'id'=>$renzhen['id'],
                    'status'=>0,
                    'sex'=>$param['sex'],
                    'addr'=>$param['addr'],
                    'zongpai'=>$param['zongpai'],
                    'phone'=>$param['phone'],
                    'isapp'=>2
                );
                $rmodel->editData($data);
            }

        }catch (\Exception $e) {
            return admin_json(-1,'添加失败'.$e->getMessage());
        }

        return admin_json(1, '添加成功');
    }
}